How to Read an Existing Excel File¶
Enumerate the Excel File Contents¶
#Load the Excel file into a PSCustomObject
$ExcelFile = Import-Excel "C:\Test\file.xlsx" -WorksheetName "Sheet1"
Visual of Data Structure¶
The File C:\Test\file.xlsx contains
After loading this data into $ExcelFile
the data is stored like:
Other Common Operations¶
Load a Column¶
$SpecificColumn = $ExcelFile."anotherHeader" #loads column with the header "anotherHeader" -- data stored in an array
Load a Row¶
Map Contents to Hashtable to Interpret Data¶
Sometimes mapping to a Hashtable is more convenient to have access to common Hashtable operations. Enumerate a Hashtable with the row's data by:
To then iterate through the enumerated Hashtable: